<?php
/**
 * SpiderController.php class file.
 * @author wudg <544038230@qq.com>
 * @date 2020/11/2- 2:42 下午
 */

namespace console\controllers;


use yii\console\Controller;
use yii\helpers\FileHelper;
use console\components\daemons\syncbatchdetail\Worker;
use yii\console\ExitCode;
use Yii;
class SyncbatchdetailController extends Controller
{


    /**
     * 是否为守护进程模式运行
     * @var bool
     */
    public $daemon = false;

    /**
     * 启动服务
     * @return int
     */
    public function actionStart()
    {


        $worker = (new Worker())->run();
        return ExitCode::UNSPECIFIED_ERROR;
    }

    /**
     * 文件日志记录
     * @param $msg
     * @throws \yii\base\Exception
     */
    private function _writeLog($msg)
    {

        $path = Yii::getAlias('@runtime/api/isv/');

        //目录如果不存就先创建目录
        if(!is_dir($path)) {
            FileHelper::createDirectory($path);
        }

        $cp = fopen($path.'sync-items-'.date('Ymd').'.log', "a+");
        $txt = "【".date('Y-m-d H:i:s',time())."】---".$msg."\r\n";
        fwrite($cp, $txt);
        fclose($cp);
    }
}
